package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsSightseeingBusApplicantParam;
import com.macro.mall.dto.BmsSightseeingBusParam;
import com.macro.mall.model.BmsSightseeingBus;
import com.macro.mall.model.BmsSightseeingBusApplicant;
import com.macro.mall.service.BmsSightseeingBusApplicantService;
import com.macro.mall.service.BmsSightseeingBusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 观光车预约Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsSightseeingBusApplicantController")
@Tag(name = "BmsSightseeingBusApplicantController", description = "观光车管理")
@RequestMapping("/sightseeingBusApplicant")
public class BmsSightseeingBusApplicantController {
    @Autowired
    private BmsSightseeingBusApplicantService bmsSightseeingBusApplicantService;

    @ApiOperation("添加观光车预约记录")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsSightseeingBusApplicantParam bmsSightseeingBusApplicantParam) throws Exception {
        BmsSightseeingBusApplicant bmsSightseeingBusApplicant =  bmsSightseeingBusApplicantService.create(bmsSightseeingBusApplicantParam);
        if (null == bmsSightseeingBusApplicant.getId()){
            return CommonResult.failed();
        }
        return CommonResult.success(bmsSightseeingBusApplicant);

    }


    @ApiOperation("修改观光车预约记录")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsSightseeingBusApplicantParam bmsSightseeingBusApplicantParam) {
        int count = bmsSightseeingBusApplicantService.update(bmsSightseeingBusApplicantParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("web分页查询观光车预约记录")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsSightseeingBusApplicant>> getList(@RequestBody BmsSightseeingBusApplicantParam bmsSightseeingBusApplicantParam) {
        List<BmsSightseeingBusApplicant> bmsSightseeingBusAplicantList = bmsSightseeingBusApplicantService.getList(bmsSightseeingBusApplicantParam);
        return CommonResult.success(CommonPage.restPage(bmsSightseeingBusAplicantList));
    }

    @ApiOperation("根据id获取观光车信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsSightseeingBusApplicant> getItem(@PathVariable Long id) {
        BmsSightseeingBusApplicant bmsSightseeingBusApplicant = bmsSightseeingBusApplicantService.getItem(id);
        return CommonResult.success(bmsSightseeingBusApplicant);
    }

    @ApiOperation("删除观光车")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        int count = bmsSightseeingBusApplicantService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


}
